import { createRequire } from 'node:module'
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

const require = createRequire(import.meta.url)
const pkg = require('./package.json')

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    open: true
  },
  build: {
    lib: {
      entry: './src/main.ts',
      fileName: (format) => `${pkg.libName}.${format}.js`,
      name: pkg.umdName,
      formats: ['umd', 'es']
    },
    rollupOptions: {
      external: ['vue'],
      output: {
        globals: {
          vue: 'Vue'
        }
      }
    }
  },
  plugins: [vue(), vueJsx()],
  resolve: {
    alias: {
      '@/example': fileURLToPath(new URL('./example', import.meta.url))
    }
  }
})
